package com.whims.MemoryError.OutOfMemoryError;

/**
 * 创建线程导致内存溢出
 * vm options: -Xss2m
 */
public class ThreadJavaVMStackOOM {

    private void dontStop(){
        while (true){

        }
    }

    public void stackLeakByThread(){
        while (true){
            Thread thread = new Thread(new Runnable() {
                public void run() {
                    dontStop();
                }
            });
            thread.start();
        }

    }

    //注意，请保存相关工作，这里有可能使系统卡死
    public static void main(String [] args) throws Throwable {
        ThreadJavaVMStackOOM oom = new ThreadJavaVMStackOOM();
        oom.stackLeakByThread();
    }


}
